home *** CD-ROM | disk | FTP | other *** search
- Path: ix.netcom.com!news
- From: giuliano@ix.netcom.com(Giuliano Carlini)
- Newsgroups: comp.lang.c++
- Subject: Re: Mutually referring header files
- Date: 11 Apr 1996 06:36:19 GMT
- Organization: Netcom
- Message-ID: <4ki993$1ov@dfw-ixnews2.ix.netcom.com>
- References: <4ked7q$8g3@dub-news-svc-1.compuserve.com>
- NNTP-Posting-Host: lbx-ca7-14.ix.netcom.com
- X-NETCOM-Date: Thu Apr 11 1:36:19 AM CDT 1996
-
- In <4ked7q$8g3@dub-news-svc-1.compuserve.com> RossBoylan@aol.com (Ross
- Boylan) writes:
- >
- >I have 2 classes A + B, defined in separate files. Each refers to and
- >messages the other. What is the best way to handle this?
- > ...
- >3) It may or may not matter that I'm actually using smart pointers, so
- >the pointer declarations are actually
- >CountedObjPtr<A> pA;
- >
- >4)
- >Also, I put no code definition in the header file (i.e., b.h contains
- >no lines of the form
- >class B {
- > void doit() {pA->hello();};
- >};
- >Such lines require more than class A;--they must actually know the
- >protocols A responds to.
- >
- >This bit of code discipline is possible for regular classes, but what
- >do I do for templates. With my compiler (MSVC++ 4.0) the header file
- >must include all the code definition.
-
- I'm not sure about the VC++ part of your question, but I'd do it
- something like this. I'm always getting my template syntax wrong,
- so beware of my stupid errors.
-
- // a.h
- #ifndef derived_h
- #define derived_h
-
- #include "base.h" // must include your base classes header.
- template<...> class X; // Try to avoid including any others.
-
- template<...> class Derived : Base<...> {
- void foo( const X& ); // Try to use only Ref's and pointers to
- void bar( const X* ); // other classes. Then you don't need to
- // include their headers
- }
-
- #endif // derived_h
-
- // derived.t
- #ifndef derived_t
- #define derived_t
-
- #include "x.h"
- #include "x.t"
-
- template< ... > Derived::foo( const X& )
- {
- ...
- }
-
- #endif // derived_t
-
- // client.cpp
- #include "derived.h"
- #include "derived.t"
- ..
-
-
- g
-